﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DBUtility;//请先添加引用
namespace TierApplication
{
    /// <summary>
    /// 类P_Version。
    /// </summary>
    [Serializable]
    public partial class P_Version
    {
        public P_Version()
        { }
        #region Model
        private string _mc;
        private int _bbh;
        private decimal? _wjdx;
        private DateTime? _xgrq;
        private string _lj;
        private string _scr;
        private DateTime? _scrq;
        private string _bz;
        /// <summary>
        /// 
        /// </summary>
        public string MC
        {
            set { _mc = value; }
            get { return _mc; }
        }
        /// <summary>
        /// 
        /// </summary>
        public int BBH
        {
            set { _bbh = value; }
            get { return _bbh; }
        }
        /// <summary>
        /// 
        /// </summary>
        public decimal? WJDX
        {
            set { _wjdx = value; }
            get { return _wjdx; }
        }
        /// <summary>
        /// 
        /// </summary>
        public DateTime? XGRQ
        {
            set { _xgrq = value; }
            get { return _xgrq; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string LJ
        {
            set { _lj = value; }
            get { return _lj; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string SCR
        {
            set { _scr = value; }
            get { return _scr; }
        }
        /// <summary>
        /// 
        /// </summary>
        public DateTime? SCRQ
        {
            set { _scrq = value; }
            get { return _scrq; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string BZ
        {
            set { _bz = value; }
            get { return _bz; }
        }
        #endregion Model


        #region  Method

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public P_Version(string MC, int BBH)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select MC,BBH,WJDX,XGRQ,LJ,SCR,SCRQ,BZ ");
            strSql.Append(" FROM [P_Version] ");
            strSql.Append(" where MC=@MC and BBH=@BBH ");
            SqlParameter[] parameters = {
					new SqlParameter("@MC", SqlDbType.VarChar),
					new SqlParameter("@BBH", SqlDbType.Int,4)};
            parameters[0].Value = MC;
            parameters[1].Value = BBH;

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["MC"] != null && ds.Tables[0].Rows[0]["MC"].ToString() != "")
                {
                    this.MC = ds.Tables[0].Rows[0]["MC"].ToString();
                }
                if (ds.Tables[0].Rows[0]["BBH"] != null && ds.Tables[0].Rows[0]["BBH"].ToString() != "")
                {
                    this.BBH = int.Parse(ds.Tables[0].Rows[0]["BBH"].ToString());
                }
                if (ds.Tables[0].Rows[0]["WJDX"] != null && ds.Tables[0].Rows[0]["WJDX"].ToString() != "")
                {
                    this.WJDX = decimal.Parse(ds.Tables[0].Rows[0]["WJDX"].ToString());
                }
                if (ds.Tables[0].Rows[0]["XGRQ"] != null && ds.Tables[0].Rows[0]["XGRQ"].ToString() != "")
                {
                    this.XGRQ = DateTime.Parse(ds.Tables[0].Rows[0]["XGRQ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LJ"] != null && ds.Tables[0].Rows[0]["LJ"].ToString() != "")
                {
                    this.LJ = ds.Tables[0].Rows[0]["LJ"].ToString();
                }
                if (ds.Tables[0].Rows[0]["SCR"] != null && ds.Tables[0].Rows[0]["SCR"].ToString() != "")
                {
                    this.SCR = ds.Tables[0].Rows[0]["SCR"].ToString();
                }
                if (ds.Tables[0].Rows[0]["SCRQ"] != null && ds.Tables[0].Rows[0]["SCRQ"].ToString() != "")
                {
                    this.SCRQ = DateTime.Parse(ds.Tables[0].Rows[0]["SCRQ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["BZ"] != null && ds.Tables[0].Rows[0]["BZ"].ToString() != "")
                {
                    this.BZ = ds.Tables[0].Rows[0]["BZ"].ToString();
                }
            }
        }

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {

            return DbHelperSQL.GetMaxID("BBH", "P_Version");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string MC, int BBH)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from [P_Version]");
            strSql.Append(" where MC=@MC and BBH=@BBH ");

            SqlParameter[] parameters = {
					new SqlParameter("@MC", SqlDbType.VarChar),
					new SqlParameter("@BBH", SqlDbType.Int,4)};
            parameters[0].Value = MC;
            parameters[1].Value = BBH;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [P_Version] (");
            strSql.Append("MC,BBH,WJDX,XGRQ,LJ,SCR,SCRQ,BZ)");
            strSql.Append(" values (");
            strSql.Append("@MC,@BBH,@WJDX,@XGRQ,@LJ,@SCR,@SCRQ,@BZ)");
            SqlParameter[] parameters = {
					new SqlParameter("@MC", SqlDbType.VarChar,100),
					new SqlParameter("@BBH", SqlDbType.Int,4),
					new SqlParameter("@WJDX", SqlDbType.Decimal,9),
					new SqlParameter("@XGRQ", SqlDbType.DateTime),
					new SqlParameter("@LJ", SqlDbType.VarChar,100),
					new SqlParameter("@SCR", SqlDbType.VarChar,100),
					new SqlParameter("@SCRQ", SqlDbType.DateTime),
					new SqlParameter("@BZ", SqlDbType.VarChar,100)};
            parameters[0].Value = MC;
            parameters[1].Value = BBH;
            parameters[2].Value = WJDX;
            parameters[3].Value = XGRQ;
            parameters[4].Value = LJ;
            parameters[5].Value = SCR;
            parameters[6].Value = SCRQ;
            parameters[7].Value = BZ;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update [P_Version] set ");
            strSql.Append("WJDX=@WJDX,");
            strSql.Append("XGRQ=@XGRQ,");
            strSql.Append("LJ=@LJ,");
            strSql.Append("SCR=@SCR,");
            strSql.Append("SCRQ=@SCRQ,");
            strSql.Append("BZ=@BZ");
            strSql.Append(" where MC=@MC and BBH=@BBH ");
            SqlParameter[] parameters = {
					new SqlParameter("@WJDX", SqlDbType.Decimal,9),
					new SqlParameter("@XGRQ", SqlDbType.DateTime),
					new SqlParameter("@LJ", SqlDbType.VarChar,100),
					new SqlParameter("@SCR", SqlDbType.VarChar,100),
					new SqlParameter("@SCRQ", SqlDbType.DateTime),
					new SqlParameter("@BZ", SqlDbType.VarChar,100),
					new SqlParameter("@MC", SqlDbType.VarChar,100),
					new SqlParameter("@BBH", SqlDbType.Int,4)};
            parameters[0].Value = WJDX;
            parameters[1].Value = XGRQ;
            parameters[2].Value = LJ;
            parameters[3].Value = SCR;
            parameters[4].Value = SCRQ;
            parameters[5].Value = BZ;
            parameters[6].Value = MC;
            parameters[7].Value = BBH;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string MC, int BBH)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [P_Version] ");
            strSql.Append(" where MC=@MC and BBH=@BBH ");
            SqlParameter[] parameters = {
					new SqlParameter("@MC", SqlDbType.VarChar),
					new SqlParameter("@BBH", SqlDbType.Int,4)};
            parameters[0].Value = MC;
            parameters[1].Value = BBH;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetModel(string MC, int BBH)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select MC,BBH,WJDX,XGRQ,LJ,SCR,SCRQ,BZ ");
            strSql.Append(" FROM [P_Version] ");
            strSql.Append(" where MC=@MC and BBH=@BBH ");
            SqlParameter[] parameters = {
					new SqlParameter("@MC", SqlDbType.VarChar),
					new SqlParameter("@BBH", SqlDbType.Int,4)};
            parameters[0].Value = MC;
            parameters[1].Value = BBH;

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["MC"] != null && ds.Tables[0].Rows[0]["MC"].ToString() != "")
                {
                    this.MC = ds.Tables[0].Rows[0]["MC"].ToString();
                }
                if (ds.Tables[0].Rows[0]["BBH"] != null && ds.Tables[0].Rows[0]["BBH"].ToString() != "")
                {
                    this.BBH = int.Parse(ds.Tables[0].Rows[0]["BBH"].ToString());
                }
                if (ds.Tables[0].Rows[0]["WJDX"] != null && ds.Tables[0].Rows[0]["WJDX"].ToString() != "")
                {
                    this.WJDX = decimal.Parse(ds.Tables[0].Rows[0]["WJDX"].ToString());
                }
                if (ds.Tables[0].Rows[0]["XGRQ"] != null && ds.Tables[0].Rows[0]["XGRQ"].ToString() != "")
                {
                    this.XGRQ = DateTime.Parse(ds.Tables[0].Rows[0]["XGRQ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LJ"] != null && ds.Tables[0].Rows[0]["LJ"].ToString() != "")
                {
                    this.LJ = ds.Tables[0].Rows[0]["LJ"].ToString();
                }
                if (ds.Tables[0].Rows[0]["SCR"] != null && ds.Tables[0].Rows[0]["SCR"].ToString() != "")
                {
                    this.SCR = ds.Tables[0].Rows[0]["SCR"].ToString();
                }
                if (ds.Tables[0].Rows[0]["SCRQ"] != null && ds.Tables[0].Rows[0]["SCRQ"].ToString() != "")
                {
                    this.SCRQ = DateTime.Parse(ds.Tables[0].Rows[0]["SCRQ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["BZ"] != null && ds.Tables[0].Rows[0]["BZ"].ToString() != "")
                {
                    this.BZ = ds.Tables[0].Rows[0]["BZ"].ToString();
                }
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM [P_Version] ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        #endregion  Method
    }
}

